//
//  NetworkManager.swift
//  DouYu
//
//  Created by 王鹏宇 on 2018/4/10.
//  Copyright © 2018年 王鹏宇. All rights reserved.
//

import UIKit
import Alamofire

enum NetMethodType {
    case get
    case post
}

class NetworkManager: NSObject {

    class func requestData(_ type : NetMethodType, URLString : String, parameters : [String : Any]? = nil, finishedCallback : @escaping (_ result : Any)->()){
        
        // 获取类型
        let method = type == .get ? HTTPMethod.get : HTTPMethod.post
        // 发送网络请求
        // 2.发送网络请求
        Alamofire.request(URLString, method: method, parameters: parameters).responseJSON { (response) in
         
            //获取结果
            guard let result = response.result.value else {
            
                print(response.result.error!)
            
                return
            }
            
            //将结果回调回去
            finishedCallback(result)
        }
        }
}
